import { WeaSearchGroup,WeaFormItem,WeaHelpfulTip,WeaUpload } from 'ecCom';
import { Row,Col } from 'antd';
import {toJS} from "mobx"
import {WeaSwitch} from "comsMobx"
import { observer} from 'mobx-react';
import { WeaLocaleProvider } from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
const view_basicToolBar = {
    uploadUrl: "/api/blog/fileupload/uploadimage", 
    startupFocus: false,
    toolbar: [],
};
const basicToolBar = {
    uploadUrl: '/api/doc/upload/uploadFile?model=reply',
    startupFocus: false,
    toolbar: [
      { name: 'markdown', items: ['Markdown'] },
      { name: 'document', items: ['Source', '-', 'Save', 'NewPage', 'Preview',  '-', 'Templates'] },
      { name: 'clipboard', items: ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo'] },
      { name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'CopyFormatting', 'RemoveFormat'] },
      { name: 'styles', items: ['Styles', 'Format', 'Font', 'FontSize'] },
      { name: 'colors', items: ['TextColor', 'BGColor'] },
      { name: 'tools', items: ['Maximize', 'ShowBlocks'] },
      { name: 'insert', items: ['Image', 'Table', 'Smiley'] }
    ],
  };

@observer
export default class CptInfo extends React.Component{

    render(){
        const { condition,form,setValidate,store  } = this.props;
        const {isFormInit} = form;
        let group = [];
        let validation = {};
        isFormInit &&  condition.fieldinfo.map((c,i) =>{
          let items = [];
          let dom ;
          c.items.map((fields,index) => {
            let hasunderline = false;
            if(fields.viewAttr == "1" || (fields.conditionType == "BROWSER" && fields.browserConditionParam.viewAttr == "1")) {hasunderline = true}  //只读样式控制
            if(fields.viewAttr == "3" || (fields.conditionType == "BROWSER" && fields.browserConditionParam.viewAttr == "3")){
                validation[fields.domkey[0]] = "required";  //添加校验规则
            }

            if(fields.conditionType == "CPTIMG"){
                let domkey = fields.domkey[0];
                dom = <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@p16xkm@${index}`}>
                <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@rwhinp@${index}`} span={24} >
                <div className="cpt-img-upload">
                    <WeaUpload ecId={`${this && this.props && this.props.ecId || ''}_WeaUpload@ti6ss8@${index}`}
                        uploadId={[domkey]}
                        uploadUrl={"/api/doc/upload/uploadFile"}
                        category='all'
                        autoUpload={true}
                        showClearAll={false}
                        multiSelection={true}
                        datas={toJS(fields.datas)}
                        listType='img'
                        limitType='jpg,gif,png'
                        imgWidth={50}
                        imgHeight={50}
                        maxUploadSize={5}
                        onChange={v => {form.updateFields({[domkey]:{value:v}}, false) }}
                        viewAttr={fields.viewAttr}
                    />
                    </div>
                </Col>
              </Row>
            }else if(fields.conditionType == "RICHTEXT"){
                if(fields.viewAttr == "1"){
                    fields.ckConfig=view_basicToolBar;
                    dom = <div className='view_basicToolBar'><WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@seei87@${index}`} fieldConfig={fields} form={form}/></div>
                }else{
                    fields.ckConfig=basicToolBar;
                    dom = <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@hbmd2b@${index}`} fieldConfig={fields} form={form}/>
                }
            }else if(fields.domkey[0] == "frozennum"){
                    dom = <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@xjxj0k@${index}`}>
                    <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@cz9a8u@${index}`} span={12}  >
                        <div style = {{paddingTop: '15px'}}><span className="c" >{fields.value}</span>
                        <WeaHelpfulTip ecId={`${this && this.props && this.props.ecId || ''}_WeaHelpfulTip@521pcz`}
                            style = {{marginLeft: '20px'}}
                            width =  {300} //如果要自定义宽度，在这里设置
                            title={this.renderTips(fields.frozennumtip)}
                            />
                       </div>
                    </Col>
                  </Row>
            
            }else if(fields.domkey[0] == "currentprice"){
                    dom = <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@s8xb2j@${index}`}>
                    <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@g62xt6@${index}`} span={12}  >
                        <div style = {{paddingTop: '15px'}}><span className="c" >{fields.value}</span>
                        <WeaHelpfulTip ecId={`${this && this.props && this.props.ecId || ''}_WeaHelpfulTip@7ab0qe`}
                            style = {{marginLeft: '20px'}}
                            width =  {300} 
                            placement="right"
                            title={"1、"+getLabel(21771, "未超过折旧年限：单独核算资产现值＝资产原值- 资产原值×(1- 残值率)×已用年限/折旧年限")+
                            "<br>2、"+getLabel(21772, "已经超过折旧年限：单独核算资产现值＝资产原值×残值率")+
                            "<br>3、"+getLabel(517768, "非单独核算资产现值＝资产数量×资产原值")+
                            "<br>4、"+getLabel(517766, "已用年限：当前日期-购置日期")}
                            />
                    </div>
                    </Col>
                </Row>
            }else if(fields.domkey[0] == "address"){
                dom = <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@wanep6@${index}`}>
                <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@wbjae0`} span={10}  >
                    <div style = {{paddingTop: '15px'}}><span className="c" >{fields.value}</span>
                   </div>
                </Col>
                {fields.value!=''&&<Col ecId={`${this && this.props && this.props.ecId || ''}_Col@41fglr`}>
                    {<div style = {{paddingTop:'15px'}}><i className='icon-coms-Map'  onClick={() =>{store.setMapDialogVisible(true)}} style={{cursor:'pointer'}}/></div>}
                </Col>}
              </Row>
            }else{
                dom =  <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@54rpp2@${index}`} fieldConfig={fields} form={form} />; 
            }

            if(hasunderline){
                items.push({
                    com:(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@9f7gvn@${index}`}
                        label={`${fields.label}`}
                        labelCol={{span: `${fields.labelcol}`}}
                        wrapperCol={{span: `${fields.fieldcol}`}} underline >
                             {dom}
                        </WeaFormItem>),
                    colSpan:1,
                  })
            }else{
                items.push({
                    com:(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@0ue7t5@${index}`}
                        error={form.getError(fields)}
                        tipPosition="bottom"
                        label={`${fields.label}`}
                        labelCol={{span: `${fields.labelcol}`}}
                        wrapperCol={{span: `${fields.fieldcol}`}}>
                             {dom}
                        </WeaFormItem>),
                    colSpan:1,
                  })
            }
            
          });
          group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@r6bp1l@${i}`} needTigger={true} title={c.title}  showGroup={c.defaultshow} items={items}/>)
        });
        setValidate(validation);
        return group;
    }

    renderTips(str){
        return <div  dangerouslySetInnerHTML={{__html:str}}></div>
    }
}



